package com.xsd.prc;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/**
 * @Description:
 * @Author: zhoufuzong
 * @Created: 2021-01-03 10:59:11
 * @Version: 1.1.0
 */

/**
 * 和 Runnable 的区别
 *
 * 有返回值
 * 有抛异常
 * 落地方法不同
 */

class  MyThreade implements Callable<Integer>{
    @Override
    public Integer call() throws Exception {
        System.out.println("**** come in callable ");
        try{TimeUnit.SECONDS.sleep(4); } catch(InterruptedException e) {e.printStackTrace();}

        return 1024;
    }
}

public class CallableDemo {


    public static void main(String[] args) throws ExecutionException, InterruptedException {
       FutureTask futureTask = new FutureTask(new MyThreade());

       new Thread(futureTask).start();
       new Thread(futureTask).start();

        System.out.println(Thread.currentThread().getName()+"\t计算完成");

        System.out.println(futureTask.get());
    }
}
